var e = function() {
    function e(e, t) {
        for (var a = 0; a < t.length; a++) {
            var n = t[a];
            n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), 
            Object.defineProperty(e, n.key, n);
        }
    }
    return function(t, a, n) {
        return a && e(t.prototype, a), n && e(t, n), t;
    };
}(), t = n(require("./components/loading")), a = n(require("./tools.js"));

function n(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

var o = require("../libs/w7/index.js"), r = function() {
    function n(e) {
        (function(e, t) {
            if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function");
        })(this, n), this.baseURL = e || "entry/wxapp/yx";
    }
    return e(n, [ {
        key: "http",
        value: function(e, t) {
            var a = this, n = 2 < arguments.length && void 0 !== arguments[2] && arguments[2], o = 3 < arguments.length && void 0 !== arguments[3] && arguments[3];
            return new Promise(function(r, u) {
                a.ajax({
                    path: e,
                    data: t,
                    hasLoading: n,
                    showAlert: o
                }).then(r).catch(u);
            });
        }
    }, {
        key: "ajax",
        value: function(e) {
            var n = this, r = e.path, u = e.data, s = e.header, i = e.method, c = e.dataType, d = e.hasLoading, l = void 0 !== d && d, f = void 0 !== (e = e.showAlert) && e;
            return new Promise(function(e, d) {
                var h = null;
                l && (h = (0, t.default)()), o.request({
                    url: n.baseURL + "&yx=" + r,
                    data: u || {},
                    header: Object.assign({}, {
                        "content-type": "application/json"
                    }, s || {}),
                    method: i || "POST",
                    dataType: c || "json",
                    success: function(t) {
                        !l || h && h(), 200 === t.statusCode ? t.data && t.data.errcode ? (f && a.default.modalText(t.data.message || "未知错误"), 
                        d(t.data)) : e(t.data) : (d(t), f && a.default.modalText("提示", "服务器出错啦 ~"));
                    },
                    fail: function(e) {
                        !l || h && h(), console.error("REQUESR ERROR: ", e), f && a.default.modalText(e.msg || "服务器出错 !"), 
                        d(e);
                    }
                });
            });
        }
    }, {
        key: "publicMethods",
        value: function(e) {
            var t = e.path, n = e.data, r = void 0 === (s = e.method) ? "GET" : s, u = e.header, s = void 0 === (s = e.dataType) ? "json" : s, i = e.success, c = e.error;
            n = Object.assign({}, n);
            o.request({
                url: this.baseURL + "&yx=" + t,
                data: n || {},
                header: Object.assign({}, {
                    "content-type": "application/json",
                    "X-Token": wx.getStorageSync("token")
                }, u || {}),
                method: r,
                dataType: s,
                success: function(e) {
                    200 === e.statusCode ? i(e.data) : (c(e), a.default.modalText("服务器出错啦 ~"));
                },
                fail: function(e) {
                    c(e), console.error(new Error(e));
                }
            });
        }
    }, {
        key: "get",
        value: function(e, t, a) {
            var n = this;
            return new Promise(function(o, r) {
                n.publicMethods({
                    path: e,
                    data: t,
                    header: a,
                    success: function(e) {
                        return o(e);
                    },
                    error: function(e) {
                        return r(e);
                    }
                });
            });
        }
    }, {
        key: "post",
        value: function(e, t, a) {
            var n = this;
            return new Promise(function(o, r) {
                n.publicMethods({
                    path: e,
                    data: t,
                    method: "POST",
                    header: a,
                    success: function(e) {
                        return o(e);
                    },
                    error: function(e) {
                        return r(e);
                    }
                });
            });
        }
    } ]), n;
}();

module.exports = new r();